package com.ly.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //交换机名称
    public static final String ITEM_TOPIC_EXCHANGE = "item_topic_exchange";
    //队列名称
    public static final String ITEM_QUEUE = "item_queue";

    //声明交换机
    @Bean(name = "itemTopicExchange")
    public Exchange getExchange() {
        return ExchangeBuilder.topicExchange(ITEM_TOPIC_EXCHANGE).durable(false).build();
    }

    //声明队列
    @Bean(name = "itemQueue")
    public Queue getQueue() {
        return QueueBuilder.durable(ITEM_QUEUE).build();
    }

    //绑定交换机
    @Bean()
    public Binding getBing(@Qualifier(value = "itemQueue") Queue queue, @Qualifier(value = "itemTopicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("item.#").noargs();
    }

}
